package xin.yangshuai.cipher01.hello.digest.md5;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5
 *
 * @author shuai
 * @date 2020/11/24
 */
public class MD5 {

    public static void main(String[] args) throws NoSuchAlgorithmException {
        String algorithm = "MD5";
        byte[] input = "hello world !".getBytes();
        MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
        byte[] digest = messageDigest.digest(input);
        StringBuffer stringBuffer = new StringBuffer();
        for (byte b : digest) {
            String x = Integer.toHexString(b & 0Xff);
            x = x.length() == 2 ? x : "0" + x;
            stringBuffer.append(x);
        }
        System.out.println(stringBuffer.toString());
    }
}
